/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.dao;

import entidades.Familia;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ribadas
 */

@Stateless
public class FamiliaDAO extends GenericoDAO<Familia> implements FamiliaDAORemote, FamiliaDAOLocal {

    public List<Familia> buscarPorNombre(String nombre) {
        Query q = em.createQuery("SELECT object(f) FROM Familia AS f "+
                                 "  WHERE  f.nombre LIKE :patron");
        q.setParameter("patron", "%"+nombre+"%");
        return q.getResultList();
    }

    public List<Familia> buscarPorAbreviatura(String abreviatura) {
        Query q = em.createQuery("SELECT object(f) FROM Familia AS f "+
                                 "  WHERE  f.abreviatura LIKE :patron");
        q.setParameter("patron", "%"+abreviatura+"%");
        return q.getResultList();

    }

    public List<Familia> buscarTodos() {
        Query q = em.createQuery("SELECT object(f) FROM Familia AS f");
        return q.getResultList();
    }

    public List<Familia> buscarTodosRango(int inicio, int tamano) {
        Query q = em.createQuery("SELECT object(f) FROM Familia AS f");
        q.setFirstResult(inicio);
        q.setMaxResults(tamano);
        return q.getResultList();
    }

    public int contador() {
        Query q = em.createQuery("SELECT count(f) FROM Familia AS f");
        return q.getFirstResult();
    }



    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")


}
